package components.scenes;

import components.Walker;
import components.direction.Direction;
import components.terrain.Terrain;

public class Slot {

	public static int DIAMETER = 20;
	
	private Terrain terrain;
	private int x;
	private int y;
	
	public Slot(int x, int y){
		this.x = x;
		this.y = y;
	}
	
	public void setTerrain(Terrain terrain) {
		this.terrain = terrain;
	}

	public boolean isSolid() {
		if (this.terrain != null){
			return this.terrain.isSolid();
		}
		else return true;
		
	}

	public boolean arrived(Walker walker) {
		return Math.abs(walker.getCenterX() - this.centerX()) <8 & Math.abs(walker.getCenterY() - this.centerY()) < 8;
	}
	
	public boolean arrived2(Walker walker, Direction dir) {
		// ARREGLAR ESTO ALGUN DIA, ES LO PEOR
		if (dir.equals(Direction.NORTH)){
			return this.centerY() > walker.getCenterY();
		} else if (dir.equals(Direction.SOUTH)){
			return this.centerY() < walker.getCenterY();
		}else if (dir.equals(Direction.EAST)){
			return this.centerX() < walker.getCenterX();
		}else return this.centerX() > walker.getCenterX();
	}
	
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public double centerX(){
		return this.x * DIAMETER + DIAMETER/2;
	}
	public double centerY(){
		return this.y * DIAMETER + DIAMETER/2;
	}
	
	public boolean isWalkeable(){
		return !this.isSolid();
	}
	
	public boolean equals(Object obj) {
        if(this == obj) {
              return true;
         }
         if (!(obj instanceof Slot)) {
                return false; 
         }
         Slot slot = (Slot)obj;
         return this.getX() == slot.getX() & this.getY() == slot.getY();

  }    
	public int hashCode () {

      return this.getX()*this.getY()*133;
  }
	
	public String toString(){
		return "(" + this.getX() + "," + this.getY() + ")";
	}

}
